<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <!--<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />-->
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
      .current1{
        background-color: #009688;
        color: white;
        pointer-events: none;
        cursor: default;
      }
    </style>
  </head>
  <body>l,
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
      <a class="layui-btn layui-btn-small flashBtn" style="line-height:1.6em;margin-top:3px;float:right" onclick="clause_page(null,0)" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i>
      </a>
    </div>
    <div class="x-body">
     <div class="layui-row">
       <form class="layui-form layui-col-mdx12 x-so" method="post" action="searchByCondition">
		   <div class="layui-input-inline">
		     <select name="lawId" >
		       <option th:each="law:${laws}" th:value="${law.id}" th:text="${law.lawsName}" th:selected="${law.id==lawId?'true':'false'}">法规4</option>
		     </select>
		   </div>
         <label>条款号：</label><input type="text" name="clauseNum" th:value="${clauseNum}" placeholder="条款号" autocomplete="off" class="layui-input">
         <label>关键词：</label><input type="text" name="keyWord" th:value="${keyWord}"  placeholder="关键词" autocomplete="off" class="layui-input">
         <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
       </form>
       <button class="layui-btn" onclick="x_admin_show('添加条款','/showModifyPage')"><i class="layui-icon"></i>添加</button>
     </div>
      <div style="height: 500px;">
        <table class="layui-table">
          <thead>
          <tr>
            <th>
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>条款号</th>
            <th>条款别名</th>
            <th>条款标题</th>
            <th>所属法规名称</th>
            <th>版本号</th>
            <th>操作</th>
          </tr>
          </thead>
          <tbody>
          <tr th:each="clause:${pageInfo.list}">
            <td th:attr="clauseId=${clause.id}">
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td th:text="${clause.clause}">1</td>
            <td th:text="${clause.alias}"></td>
            <td th:text="${clause.titel}">适用范围</td>
            <td th:text="${clause.laws.lawsName}">云航飞机适航标准</td>
            <td th:text="${clause.laws.lawsVersion}">R4</td>
            <td class="td-manage">
              <a title="编辑" th:onclick="x_admin_show('编辑',[['showModifyPage?id='+${clause.id}+'&clause='+${clause.clause}+'&alias='+${clause.alias}+'&titel='+${clause.titel}+'&lawsId='+${clause.lawsId}+'&catalogId='+${clause.catalogId}]]);" href="javascript:;">
                <i class="layui-icon">&#xe642;</i>
              </a>
              <a title="删除" class="delBtn" th:onclick="clause_del(this,[[${clause.id}]]);" href="javascript:;">
                <i class="layui-icon">&#xe640;</i>
              </a>
            </td>
          </tr>
          <tr style="text-align: center">
            <td colspan="7" th:if="${#lists.isEmpty(pageInfo.list)}">没有找到您要查询的内容，请换一个试试</td>
          </tr>
          </tbody>
        </table>
      </div>

      <div class="page">
        <div th:attr="nowPage=${pageInfo.pageNum}">
          <a class="prev" id="prvePage" href="javascript:void(0)" onclick="clause_page(this,-1)">&lt;&lt;</a>
          <a th:each="num:${pageInfo.navigatepageNums}" th:style="${pageInfo.pageNum==num?'background-color:#009688;color:white':''}" th:text="${num}" th:class="${pageInfo.pageNum==num?'num current1':'num'}" href="javascript:void(0)" onclick="clause_page(this,0)">1</a>
          <a class="next" id="nextPage"  href="javascript:void(0)" onclick="clause_page(this,1)">&gt;&gt;</a>
        </div>
      </div>
    </div>
    <script>
      layui.use(['form','layer','laydate'], function(){
        var laydate = layui.laydate;
        layer = layui.layer;
      });
      var form = layui.form;

      /*删除*/
      function clause_del(obj,id){
          layer.confirm('确认要删除吗？',{icon:3,title:'提示信息'},function(index){
              $.ajax({
                  type:"post",
                  url:"/delClauseById",
                  data:{id:id},
                  dataType:"json",
                  success:function(data){
                      if(data.status==1){
                          $(obj).parents("tr").remove();
                          layer.msg(data.info,{icon:6,time:1000});
                      } else{
                          layer.msg(data.info,{icon:5,time:1000});return false;
                      }
                  }
              });
          });
      }

      /*换页*/
      function clause_page(obj,condition){
          if (obj == null){
              obj = $("a[class='num current1']");
          }
          var pageNum = pageNum=$(obj).text();
          layer = layui.layer;//弹出层
          if (condition==-1){
              pageNum = Number($(obj).parent().attr("nowPage")) - Number(1);
              if (Number(pageNum)*1 < Number($(obj).parent().children().eq(1).text())*1){
                  layer.msg('已经是第一页了~',{icon:5,time:1000});return false;
              }
          }else if(condition==1){
              pageNum = Number($(obj).parent().attr("nowPage"))+Number(1);
              if (Number(pageNum)*1 > Number($(obj).parent().children().eq(-2).text())*1){
                  layer.msg('已经是最后一页了~',{icon:5,time:1000});return false;
              }
          }
          $.ajax({
              type:"post",
              url:"/searchByConditionToPage",
              data:{pageNum:pageNum},
              dataType:"json",
              success:function(data){
                  if(data.status==1){
                      //发异步删除数据
                      $("tbody").children().remove();
                      var htm = "";
                      $.each(data.pageInfo.list,function(index,value){
                          htm+=" <tr>\n" +
                              "            <td>\n" +
                              "              <div class=\"layui-unselect header layui-form-checkbox\" lay-skin=\"primary\"><i class=\"layui-icon\">&#xe605;</i></div>\n" +
                              "            </td>\n" +
                              "            <td>"+value.clause+"</td>\n" +
                              "            <td>"+(value.alias=="null"||value.alias==""||value.alias==null||value.alias==undefined?"":value.alias)+"</td>\n" +
                              "            <td>"+value.titel+"</td>\n" +
                              "            <td>"+value.laws.lawsName+"</td>\n" +
                              "            <td>"+value.laws.lawsVersion+"</td>\n" +
                              "            <td class=\"td-manage\">\n" +
                              "              <a title=\"编辑\"  onclick=\"x_admin_show('编辑','showModifyPage?id="+value.id+"&clause="+value.clause+"&alias="+value.alias+"&titel="+value.titel+"&lawsId="+value.lawsId+"&catalogId="+value.catalogId+"&content="+(value.content+"").replace(/[\r\n]/g,"")+"')\" href=\"javascript:void(0);\">\n" +
                              "                <i class=\"layui-icon\">&#xe642;</i>\n" +
                              "              </a>\n" +
                              "              <a title=\"删除\" class=\"delBtn\" onclick=\"clause_del(this,"+value.id+")\" href=\"javascript:void(0);\">\n" +
                              "                <i class=\"layui-icon\">&#xe640;</i>\n" +
                              "              </a>\n" +
                              "            </td>"
                              "          </tr>";
                      });
                      $("input[name='clauseNum']").val(data.clauseNum);
                      $("input[name='keyWord']").value =  data.keyWord;
                      $("tbody").html(htm);
                      $(obj).parent().attr("nowPage",data.pageInfo.pageNum);
                      $(obj).parent().children().removeClass("current1").css('background-color','').css('color','');
                      if(condition==0){
                          $(obj).addClass("current1").css('background-color','#009688').css('color','white');
                      }else{
                          $(obj).parent().children(":contains('"+data.pageInfo.pageNum+"')").addClass("current1").css('background-color','#009688').css('color','white');
                      }
                  } else{
                      layer.msg(data.info,{icon:5,time:1000});return false;
                  }
              }
          });
      }
    </script>
  </body>
</html>